GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson - #50781
GH-50779: [C++][Parquet] Replace remaining RapidJSON usage with simdjson#50781Reranko05 wants to merge 2 commits into
Conversation
|
|
d026d1f to
0230946
Compare
|
I'm migrating
With RapidJSON this was straightforward because the DOM is reusable, but with Is the expected approach here to restructure the code into a single pass, or is there another way to serialize an already-inspected Thanks! |
|
As per docs here you could probably use the // Inspect crs_object...
// If it was not a recognized lon/lat CRS:
ARROW_ASSIGN_OR_RAISE(
auto ignored,
::arrow::internal::GetSimdjsonResult(
crs_object.reset(), "Failed to reset 'crs' object: "));
ARROW_ASSIGN_OR_RAISE(
auto raw_crs,
::arrow::internal::GetSimdjsonResult(
crs_object.raw_json(), "Failed to get raw 'crs' JSON: "));
return std::string(raw_crs);Check also |
|
Thanks @rok, However, one test still fails because Would you prefer keeping the previous compact formatting or preserving the original JSON formatting? |
|
@Reranko05 let's avoid behavior changes. Perhaps we can use simdjson::minify? |
270af67 to
777999e
Compare
|
|
||
| # Add RapidJSON & simdjson libraries | ||
| list(APPEND PARQUET_SHARED_PRIVATE_LINK_LIBS RapidJSON simdjson::simdjson) | ||
| list(APPEND PARQUET_STATIC_LINK_LIBS RapidJSON simdjson::simdjson) |
|
I also see many RapidJSON references in cpp/cmake_modules/ThirdpartyToolchain.cmake. Are we ready to remove those yet? (I don't know, hence the question) |
| if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs); | ||
| string.ok()) { | ||
| if (*string == "EPSG:4326" || *string == "OGC:CRS84") { |
There was a problem hiding this comment.
Can we avoid if (...; ...) for readability?
| if (auto string = ::arrow::internal::GetJsonAs<std::string_view>(json_crs); | |
| string.ok()) { | |
| if (*string == "EPSG:4326" || *string == "OGC:CRS84") { | |
| auto crs_string_result = ::arrow::internal::GetJsonAs<std::string_view>(json_crs); | |
| if (crs_string_result.ok()) { | |
| auto crs_string = *crs_string_result; | |
| if (crs_string == "EPSG:4326" || crs_string == "OGC:CRS84") { |
| auto code_string = ::arrow::internal::GetJsonAs<std::string_view>(code); | ||
|
|
||
| if (code_string.ok()) { | ||
| if ((authority_string == "OGC" && *code_string == "CRS84") || | ||
| (authority_string == "EPSG" && *code_string == "4326")) { |
There was a problem hiding this comment.
How about using _result suffix for arrow::Result variable for readability?
| auto code_string = ::arrow::internal::GetJsonAs<std::string_view>(code); | |
| if (code_string.ok()) { | |
| if ((authority_string == "OGC" && *code_string == "CRS84") || | |
| (authority_string == "EPSG" && *code_string == "4326")) { | |
| auto code_string_result = ::arrow::internal::GetJsonAs<std::string_view>(code); | |
| if (code_string_result.ok()) { | |
| auto code_string = *code_string_result; | |
| if ((authority_string == "OGC" && code_string == "CRS84") || | |
| (authority_string == "EPSG" && code_string == "4326")) { |
| json_crs.Accept(writer); | ||
| return buffer.GetString(); | ||
| RETURN_NOT_OK(::arrow::internal::GetSimdjsonResult(crs_object.reset(), | ||
| "Failed to reset 'crs' object: ") |
There was a problem hiding this comment.
It seems that all GetSimdjsonResult() messages have : suffix. How about adding it automatically?
diff --git a/cpp/src/arrow/util/simdjson_internal.h b/cpp/src/arrow/util/simdjson_internal.h
index 8ffb741da4..187dd3aaa5 100644
--- a/cpp/src/arrow/util/simdjson_internal.h
+++ b/cpp/src/arrow/util/simdjson_internal.h
@@ -85,7 +85,7 @@ template <typename T>
Result<T> GetSimdjsonResult(simdjson::simdjson_result<T> result, std::string_view error) {
T value;
if (auto error_code = std::move(result).get(value); error_code != simdjson::SUCCESS) {
- return Status::Invalid(error, simdjson::error_message(error_code));
+ return Status::Invalid(error, ": ", simdjson::error_message(error_code));
}
return value;
}(BTW, GetSimdjsonResult() name may be a bit strange because it doesn't return simdjson::result<T>. It gets arrow::Result<T> from simdjson::result<T>. ResolveSimdjsonResult(), SimdjsonResultToArrow() or something may be better.)
| ::arrow::json::JsonWriter writer; | ||
| writer.String(crs); | ||
|
|
||
| auto escaped = writer.GetString().ValueUnsafe(); |
There was a problem hiding this comment.
Should we change the return type to arrow::Result<std::string> from std::string to propagate an error?
| json << R"(, "crs": )" << buffer.GetString(); | ||
| ::arrow::json::JsonWriter writer; | ||
| writer.String(crs); | ||
| json << R"(, "crs": )" << writer.GetString().ValueUnsafe(); |
There was a problem hiding this comment.
Can we use JsonWriter for all JSON build instead of mixing manual JSON build and JsonWriter build?
Rationale for this change
This PR continues the simdjson migration by replacing the remaining RapidJSON usages under
cpp/src/parquetwith simdjson andJsonWriter. It also removes the remaining unnecessary RapidJSON dependencies from the Parquet test target and Meson build configuration.What changes are included in this PR?
reader_test.ccwith simdjson.geospatial/util_json_internal.ccwith simdjson andJsonWriter.types.ccwithJsonWriter.rapidjson_depdependency fromcpp/src/parquet/meson.build.CMakeLists.txt.